package protocol.register;

import java.io.ByteArrayOutputStream;

import org.jboss.netty.buffer.ChannelBuffer;

import protocol.BasicProtocol;
import protocol.Iprotocol;
import util.ProtocolUtils;
import config.SystemDefine;

public class Register_protocol extends BasicProtocol implements Iprotocol {

	private String names = "";
	private String password = "";

	private int sex = 0;
	private int result = 0;

	private int errorId = 0;

	public Register_protocol() {
		Type = SystemDefine.getInstance().getRegister_ID();
	}

	public void read(ChannelBuffer buffer) {
		names = decodeString(buffer);
		password = decodeString(buffer);
		sex = buffer.readInt();
	}

	@Override
	public byte[] write() {

		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

		byte[] typeByteArr = ProtocolUtils.int2byteArray(Type);
		byte[] resultArr = ProtocolUtils.int2byteArray(result);

		enCodeFormat(outputStream, typeByteArr);
		enCodeFormat(outputStream, resultArr);

		return outputStream.toByteArray();
	}

	public int getResult() {
		return result;
	}

	public void setResult(int result) {
		this.result = result;
	}

	public String getNames() {
		return names;
	}

	public void setNames(String names) {
		this.names = names;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public int getSex() {
		return sex;
	}

	public void setSex(int sex) {
		this.sex = sex;
	}
}
